Mathematics and Statistics

Assignment 8 Question 11

Test for a central limit theorem, by taking sum of N random numbers. Is the sum normally distributed?

Method

Taken as input
N - Number of samples
n - sample size
LRange - Lower limit of range from which samples are drawn
URange - Upper limit of range from which samples are drawn

Range = set of all integers between LRange and URange

In [1]:
import numpy as np
import plotly.graph_objects as go
from scipy.stats import kurtosis, skew
In [2]:
N = int(input("Enter number of samples: "))#100000
n = int(input("Enter sample size: "))#100
LRange = int(input("Enter Lower Limit: "))#1
URange = int(input("Upper Limit: "))#100
X = np.random.randint(LRange, URange, (N, n));
X = X.sum(axis=1)
Enter number of samples: 100000
Enter sample size: 100
Enter Lower Limit: 1
Upper Limit: 100

Plotting histogram of new variable to get frequency distribution and normalising to get probability

In [3]:
fig = go.Figure()
fig.add_trace(go.Histogram(
    x=X,
    histnorm='probability',
    marker_color='#330C73',
    opacity=0.75
))

fig.update_layout(
    title_text='Probability Distribution of X', # title of plot
    xaxis_title_text='X', # xaxis label
    yaxis_title_text='Probability', # yaxis label
)

fig.show()

Standardizing the new variable to make mean 0 and std deviation 1

Plotting histogram to get probability distribution of Z

In [4]:
#Standardising value
Z = (X - np.mean(X))/np.std(X)

fig = go.Figure()
fig.add_trace(go.Histogram(
    x=X,
    histnorm='probability',
    marker_color='#330C73',
    opacity=0.75
))

fig.update_layout(
    title_text='Probability Distribution of Z', # title of plot
    xaxis_title_text='Z', # xaxis label
    yaxis_title_text='Probability', # yaxis label
)

fig.show()

The bell shaped graph leads us to believe that the probability distribution of the new random variable X and it's standardized equivalent Z is normal

Additionally computed moment coefficient of skewness and kurtosis. The value should ideally be 0 for a normal distribution

Skewness

  • If the skewness is between -0.5 and 0.5, the data are fairly symmetrical
  • If the skewness is between -1 and – 0.5 or between 0.5 and 1, the data are moderately skewed
  • If the skewness is less than -1 or greater than 1, the data are highly skewed
In [5]:
print("Moment coefficient of Skewness(ideally 0): ",skew(X))
print("Moment coefficient of Kurtosis(ideally 0)(after 3 subtracted): ",kurtosis(X))
Moment coefficient of Skewness(ideally 0):  -0.013068922344556672
Moment coefficient of Kurtosis(ideally 0)(after 3 subtracted):  0.007995022471792623

Clearly the values of moment coefficient of skewness and Kurtosis are small and hence this data is close to be normally distributed

In [ ]: